﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InputState.cs" company="">
//   
// </copyright>
// <summary>
//   The input state.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

/*
 * Author: Juan Mompean Esteban
 * Created: 26-11-2011
 */
namespace ITU_vs_Zombies.Menu
{
    using Microsoft.Xna.Framework.Input;

    /// <summary>
    /// The input state.
    /// </summary>
    public class InputState
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="InputState"/> class.
        /// </summary>
        public InputState()
        {
            this.CurrentKeyboardStates = new KeyboardState();

            this.LastKeyboardStates = new KeyboardState();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets CurrentKeyboardStates.
        /// </summary>
        public KeyboardState CurrentKeyboardStates { get; private set; }

        /// <summary>
        /// Gets LastKeyboardStates.
        /// </summary>
        public KeyboardState LastKeyboardStates { get; private set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The is key pressed.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The is key pressed.
        /// </returns>
        public bool IsKeyPressed(Keys key)
        {
            return this.CurrentKeyboardStates.IsKeyDown(key);
        }

        /// <summary>
        /// The is new key press.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The is new key press.
        /// </returns>
        public bool IsNewKeyPress(Keys key)
        {
            return this.CurrentKeyboardStates.IsKeyDown(key) && this.LastKeyboardStates.IsKeyUp(key);
        }

        /// <summary>
        /// The update.
        /// </summary>
        public void Update()
        {
            this.LastKeyboardStates = this.CurrentKeyboardStates;

            this.CurrentKeyboardStates = Keyboard.GetState();
        }

        #endregion
    }
}